import os
import time

from selenium.common import NoSuchElementException

from base.base_page import BasePage


class HomePage(BasePage):
    """
    定义首页中的各类功能与操作
    文档扫描
    拍图识字
    拍图转Excel
    拍图转Word
    证件扫描
    """

    # 隐私政策-同意
    def btn_agree(self):
        return self.by_id(self.HW_ENV + "dialog_privacy_protocol_use").click()

    # 首次进入APP跳转快速登录页面，左上角x按钮
    def btn_close(self):
        return self.by_id(self.HW_ENV + "navibar_back").click()

    def btn_documents_scan(self):
        return self.by_uiautomator('new UiSelector().text("文档扫描")').click()

    def btn_text_recognize(self):
        return self.by_uiautomator('new UiSelector().text("拍图识字")').click()

    def btn_img2word(self):
        return self.by_uiautomator('new UiSelector().text("拍图转Word")').click()

    def btn_img2excel(self):
        return self.by_uiautomator('new UiSelector().text("拍图转Excel")').click()

    def btn_hw_recognize(self):
        return self.by_uiautomator('new UiSelector().text("手写识别")').click()

    def btn_tools(self):
        return self.by_uiautomator('new UiSelector().text("工具")').click()

    def go_home_page(self):
        return self.by_uiautomator('new UiSelector().text("首页")').click()

    def go_docs_page(self):
        return self.by_uiautomator('new UiSelector().text("文档")').click()

    def go_my_page(self):
        return self.by_uiautomator('new UiSelector().text("我的")').click()

    def import_picture(self):
        return self.by_uiautomator('new UiSelector().text("导入图片")').click()

    def import_pdf(self):
        return self.by_uiautomator('new UiSelector().text("导入PDF")').click()

    # 同意隐私政策并关闭快速登录页面
    def func_policy_agree(self):
        try:
            self.driver.implicitly_wait(1)
            self.btn_agree()
        except NoSuchElementException:
            pass
        try:
            self.driver.implicitly_wait(3)
            # WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(By.ID, self.HW_ENV + "navibar_back"))
            self.btn_close()
        except NoSuchElementException:
            pass
